<template>
	<view class="friends">
		<Navbar>好友列表</Navbar>
		<view class="tabs">
			<view class="item" :class="active==1?'active':''" @click="changeActive(1)">一级好友</view>
			<view class="item" :class="active==2?'active':''" @click="changeActive(2)">二级好友</view>
		</view>
		<scroll-view scroll-y class="scroll_view" @scrolltolower="loadmore">
			<view class="item" v-for="item in list">
				<view class="avatar">
					<image :src="`${baseImageUrl}/role/11.png`" v-if="item.role_id==1"></image>
					<image :src="`${baseImageUrl}/role/21.png`" v-else-if="item.role_id==2"></image>
					<image :src="`${baseImageUrl}/role/31.png`" v-else-if="item.role_id==3"></image>
					<image :src="`${baseImageUrl}/role/41.png`" v-else-if="item.role_id==4"></image>
					<image :src="`${baseImageUrl}/role/51.png`" v-else></image>
				</view>
				<view class="item_view">
					<view class="title">{{item.show_phone}}</view>
					<view class="time">购买数量：{{item.buy_number}}</view>
				</view>
				<view class="status" v-if="item.real_status==1">已激活</view>
				<view class="status" v-else>未激活</view>
			</view>
			<u-loadmore :status="loadmore_status" :color="$store.state.loadmoreColor"
				:lineColor="$store.state.loadmoreColor" line @loadmore="loadmore" />
		</scroll-view>
	</view>
</template>

<script>
	import {
		userSon,
		userSonTwo
	} from '@/request/api.js';
	export default {
		data() {
			return {
				active: 1,
				list: []
			}
		},
		onLoad() {
			this.getList();
		},
		methods: {
			async getList() {
				let res;
				if (this.active == 1) {
					res = await userSon({
						page: this.page,
						limit: this.limit
					});
				}
				if (this.active == 2) {
					res = await userSonTwo({
						page: this.page,
						limit: this.limit
					});
				}
				let {
					list
				} = res;
				this.last_page = list.last_page;
				list = list.list;
				this.list = this.page == 1 ? list : [...this.list, ...list];
				this.loadmore_status = this.last_page == this.page ? 'nomore' : 'loadmore';
			},
			changeActive(key) {
				this.active = key;
				this.page = 1;
				this.list = [];
				this.getList();
			},
			loadmore() {
				if (this.page < this.last_page) {
					this.page++;
					this.getList();
				}
			}
		}
	}
</script>
</script>

<style scoped lang="scss">
	.friends {
		height: 100vh;
		background: #29170D;
		overflow: hidden;

		.tabs {
			width: 100%;
			height: 100rpx;
			margin: 0 auto;
			padding: 0 15rpx;
			box-sizing: border-box;
			background-color: rgba(31, 11, 5, 0.6);
			display: flex;
			justify-content: center;
			align-items: center;

			.item {
				width: 300rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 36rpx;
				font-weight: 400;
				font-family: LiSu;
				margin: 0 40rpx;

				&.active {
					color: #494338;
					background: url(#{$baseImageUrl}/common/active.png) no-repeat;
					background-size: 100% 100%;
				}
			}
		}

		.scroll_view {
			height: calc(100vh - 100rpx - #{$navbarHeight});
			padding: 10rpx 30rpx;
			box-sizing: border-box;

			.item {
				width: 100%;
				height: 116rpx;
				margin-top: 20rpx;
				padding: 0 30rpx;
				box-sizing: border-box;
				background: url(#{$baseImageUrl}/common/item_690_116.png) no-repeat;
				background-size: 100% 100%;
				display: flex;
				justify-content: space-between;
				align-items: center;
				position: relative;

				.status {
					color: #494338;
					font-size: 28rpx;
					font-weight: 400;
					font-family: SimSun;
					position: absolute;
					right: 25rpx;
					top: 12rpx;
					z-index: 2;
				}

				.avatar {
					width: 100rpx;
					height: 100rpx;
					background: url(#{$baseImageUrl}/bg/avatar.png) no-repeat;
					background-size: 100% 100%;
					display: flex;
					justify-content: center;
					align-items: center;

					image {
						width: 100rpx;
						height: 100rpx;
					}
				}

				.item_view {
					flex: 1;
					padding: 0rpx 20rpx;
					box-sizing: border-box;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.title {
						color: #494338;
						font-size: 36rpx;
						font-weight: 400;
						font-family: LiSu;
					}

					.time {
						color: #494338;
						font-size: 24rpx;
						font-weight: 400;
						font-family: SimSun;
					}
				}
			}
		}
	}
</style>